import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {  //类似于组件的data
    num:5,
    msg: 'hello vuex',
    list: [1,2,3],
    person: {
      name: '张三',
      nickname: '法外狂徒'
    }
  },
  mutations: { //通过mutation在组件中修改state数据
    updateNum(state,newState) {//更新num
      state.num=newState
    },
    addNum(state) {//更新
      state.num++
    },
    subNum(state) {//更新
      state.num--
    },
    resetNum(state) {//重置num
      state.num=1
    }
  },
  actions: {
  },
  modules: {
  }
})
